package cn.bdqn.controller;

import cn.bdqn.pojo.Bank;
import cn.bdqn.pojo.Banner;
import cn.bdqn.service.AnnouncementService;
import cn.bdqn.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 正文
 * @date 2020/6/25 - 10:55
 */
@Controller
@ResponseBody
@RequestMapping("Banner")
//banner图
public class BannerController {
    @Autowired
    private BannerService bannerService;
    //banner图查询
    @RequestMapping("/list")
    public String getlist(){
        List<Banner> list = bannerService.getList();
        return "list";
    }
    //跳转banner图添加页面
    @RequestMapping("/add")
    public String add(){
        return "add";
    }
    //banner图添加成功返回首页
    @RequestMapping("addusr")
    public String add(Banner banner) {
        bannerService.add(banner);
        return "redirect:/list";
    }
    //根据id修改跳转修改页面
    @RequestMapping("/update/{id}")
    public String update(@PathVariable int id, Model model){
        List<Banner> list=bannerService.getListById(id);
        model.addAttribute("list",list);
        return "update";
    }
    //修改成功返回首页
    @RequestMapping("/upd")
    public String upd(Banner banner){
        bannerService.update(banner);
        return "redirect:/list";
    }
    //删除banner图
    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable int id){
        bannerService.delete(id);
        return "redirect:/list";
    }
}
